package com.atcjx.controller;

import com.atcjx.MyUtils.ResultFactory;
import com.atcjx.pojo.Result;
import com.atcjx.service.FileServiceImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName FileController.java
 * @Description TODO
 * @createTime 2021年10月10日 15:55:00
 */
@RestController
public class FileController {
    @Autowired
    FileServiceImpl fileService;

    @ApiOperation("返回Gitee图床的图片地址")
    @GetMapping("/pics")
    public Result getPics(
            @ApiParam("页码")
            @RequestParam(required = false, defaultValue = "1") Integer page,
            @ApiParam("数量")
            @RequestParam(required = false,defaultValue = "15") Integer limit) {
        Object pic = fileService.getPic(page, limit);
        return ResultFactory.successWithData(pic);
    }

    @ApiOperation("删除图库中指定URL的图片")
    @DeleteMapping("/deleteImgByURL")
    public Result deleteImgByURL(
            @ApiParam("需要删除图片的URL地址")
            @RequestParam(required = true,value = "url") String url
    ) {
        fileService.deleteImgByURL(url);
        return ResultFactory.success("删除成功");
    }
}
